﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Newtonsoft.Json;

namespace LearnTest
{
    public static class IQueryableExtensions
    {
        public static IQueryable<T> Where<T>(this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate)
        {
            return condition ? query.Where(predicate) : query;
        }
    }
    class Program
    {

        static void Main(string[] args)
        {
            int cccc = 0;
            try
            {
                int abv = 1 / cccc;
            }
            catch (Exception ex)
            {
                if (cccc == 1)
                    return;
                throw;
            }

            List<long> idlist = new List<long>
            {
                1,2,3,4,5
            };

            //第一种
            var mailStr = "";
            foreach (var mail in idlist)
            {
                mailStr += "'" + mail.ToString() + "'" + ",";
            }
            mailStr = mailStr[0..^1];
            Console.WriteLine(mailStr);

            //第二种
            Console.WriteLine(string.Join(",", idlist.Select(o => $"{o}")));
            Console.WriteLine($"({string.Join(",", idlist.Select(x => $"{x}"))})");

            long manualTypeId = 11;
            string recordSql = $@"SELECT	id, manualtypeid, .`name`, 	filename, url, createdate
                                    FROM	manualrecord
                                    WHERE manualtypeid = {idlist}";

            Console.WriteLine(recordSql);

            Console.ReadLine();

            var apath = @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F1112%2F012519160112%2F1Z125160112-4.jpg&refer=http%3A%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652145834&t=6e769ecf47455e1a410335d81e8b23e8";
            var bpath = @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F4k%2Fs%2F02%2F2109242332225H9-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652145834&t=92df9bbf5263ab9cc4459fc3dd2e1da9";

            HeChengPic(apath, bpath);

            Console.ReadLine();


            var f1 = new f()
            {
                id = null,
                dt = DateTime.Now,
                name = "xiOwang"
            };

            f ff = null;
            var xxx = ff?.id;

            var f2 = (fu)f1;



            var attach = JsonConvert.SerializeObject(new { OrderId = 1, TenantId = 2 });
            var attach2 = JsonConvert.DeserializeAnonymousType(attach, new { OrderId = 0, TenantId = 0 });

            Console.WriteLine(attach);


            IDo x = new A() { };
            x.Do();

            IDo a = new B() { MyProperty = 10 };
            a.Do();
            Console.WriteLine(((B)a).MyProperty);

            A c = new C() { MyProperty = 100 };
            c.Do();
            Console.WriteLine(((C)c).MyProperty);

            C c1 = new C() { MyProperty = 1000 };
            c1.Do();
            A a1 = c1;
            C c2 = (C)a1;
            Console.WriteLine(c2.MyProperty);

            Console.ReadKey();
        }

        private static void HeChengPic(string dituUrl, string scUrl)
        {

            var webC = new System.Net.WebClient();
            var bmp = new Bitmap(webC.OpenRead(dituUrl));
            var scbmp = new Bitmap(webC.OpenRead(scUrl));

            Graphics g = Graphics.FromImage(bmp);
            g.DrawImage(scbmp, 20, 20, scbmp.Width, scbmp.Height);

            bmp.Save("1", ImageFormat.Jpeg);
            g.Dispose();
        }
    }


    class A : IDo
    {
        public DateTime? ValidAappointmentStartDate { get; set; }

        public virtual void Do()
        {
            if (ValidAappointmentStartDate < DateTime.Now)
            {
                Console.WriteLine("Success");
            }

            Console.WriteLine($"我是{nameof(A)}");
        }
    }

    class B : IDo
    {
        public void Do()
        {
            Console.WriteLine($"我是{nameof(B)}");
        }

        public int MyProperty { get; set; }
    }

    class C : A
    {
        public override void Do()
        {
            Console.WriteLine($"我是{nameof(C)}");
        }

        public int MyProperty { get; set; }
    }

    interface IDo
    {
        void Do();
    }

    class fu
    {
        public virtual string MyProperty { get; }
    }

    class f : fu
    {
        public int? id { get; set; }
        public string name { get; set; }
        public DateTime dt { get; set; }

        /// <summary>
        /// 职务列表
        /// </summary>
        public string[] PositionNameList { get; set; }

        public override string MyProperty => JsonConvert.SerializeObject(new { id, name, dt });
    }


}
